package mobmap.info;

import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.midlet.MIDlet;

import mobmap.conf.Config;


public class Informacoes extends Canvas implements CommandListener {

	private Displayable anterior;
	private MIDlet midlet;
	Command voltar = new Command("Voltar", Command.BACK, 3);
	
	private int y = 4;
	

	public Informacoes(String title, Displayable displayable, MIDlet midlet) {
		setTitle(title);
		anterior = displayable;
		this.midlet = midlet;

		addCommand(voltar);
		setCommandListener(this);
	}

	public void commandAction(Command command, Displayable displayable) {
		if (command == voltar)
			Display.getDisplay(midlet).setCurrent(anterior);
	}


	protected void paint(Graphics g) {
		g.setColor(255, 255, 255);
		g.fillRect(0, 0, getWidth(), getHeight());
		g.setFont(Font.getFont(Font.FONT_STATIC_TEXT));

		g.setColor(0,0,0);
		write(g, y, " MobMap - v1.0");
		write(g, y, " Desenvolvido por: ");
		write(g, y, " Ulisses Constantini ");
		write(g, y, "   ano 2009    ");
		write(g, y, "Mapa: " + Config.MAP_NAME);
		write(g, y, "Latitude: " + Config.LAT_INICIAL);
		write(g, y, "Longitude: " + Config.LNG_INCIAL);
		write(g, y, "Mem. Total: "+Runtime.getRuntime().totalMemory()/8192 + "KB");
		write(g, y, "Mem. Livre: "+Runtime.getRuntime().freeMemory()/8192 + "KB");

	}

	public int write(Graphics g, int y, String s) {
		g.drawString(s, 4, y, Graphics.LEFT | Graphics.TOP);
		this.y+=g.getFont().getHeight();
		return y;
	}
}
